
package nativesql.scalar;

import java.util.List;

import org.hibernate.Query;

import com.e885.hibernate.HibernateSessionFactory;
import com.e885.log.E885Logger;

/**
 * 使用 scalar 強制轉換型別, 使用多個 table.<br>
 * 如： DISTRICT, COUNTY 要取得 DISTRICT.NAME 和 COUNTY.NAME 只由一行 SQL Statement 取得.<br>
 * 使用 xml document
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class ScalarNativeSQLXML3
{
	private String queryName = "ScalarNativeSQLXML3";

	/**
	 * 查詢深坑鄉
	 */
	private String districtId = "222";

	public static void main( String[] args )
	{
		new ScalarNativeSQLXML3();
	}

	@SuppressWarnings( "unchecked" )
	public ScalarNativeSQLXML3()
	{
		Query query = HibernateSessionFactory.getSession().getNamedQuery( queryName );

		query.setParameter( "districtId", districtId );

		List< Object[] > list = query.list();

		for( int i = 0; i < list.size(); i++ )
		{
			Object[] objs = list.get( i );

			E885Logger.testLog.debug( "=======================================================" );
			E885Logger.testLog.debug( "County Name:" + ( String )objs[ 0 ] );
			E885Logger.testLog.debug( "District Id:" + ( String )objs[ 1 ] );
			E885Logger.testLog.debug( "District Name:" + ( String )objs[ 2 ] );
		}
	}

}
